JsPromise

public interface JsPromise implements JsObject, Closeable

A JavaScript Promise.

Allows using Java code as promise handlers. The Promise object is alive while the web page where it was created is loaded. When the web page is unloaded, all the JavaScript objects are disposed. An attempt to access the already disposed JavaScript Promise will lead to the IllegalStateException.

Usage example:


    JsPromise jsPromise = frame.executeJavaScript("Promise.resolve('Resolved')");
    jsPromise.then(results -> System.out.println(results[0]));
  

Functions

Link copied to clipboard
public abstract T call<T>(String methodName, Array<Object> args)
Executes the function with the given methodName and the args in the JavaScript object.
Link copied to clipboard
public abstract JsPromise catchError(JsPromiseHandler onRejected)
Registers a rejection handler for this promise and returns a new one.
Link copied to clipboard
public abstract void close()
Closes this JavaScript object.
public abstract void close()
Link copied to clipboard
public abstract JsPromise finallyExecute(JsPromiseHandler onFinally)
Registers a handler that will be invoked if the promise is settled (fulfilled/rejected) and returns a new promise.
Link copied to clipboard
public abstract Frame frame()
Returns the Frame instance of this JavaScript object.
Link copied to clipboard
public abstract boolean hasProperty(String name)
Checks whether this JavaScript object or any of its prototypes has an enumerable property with the given name.
Link copied to clipboard
public abstract boolean isClosed()
Returns true if the current object is closed.
Link copied to clipboard
public abstract List<String> ownPropertyNames()
Returns an immutable list of the names of the properties of this JavaScript object, both enumerable and non-enumerable, excluding the properties from the prototype objects.
Link copied to clipboard
public abstract Optional<T> property<T>(String name)
Returns an Optional describing the value of the JavaScript object's property with the given name or an empty Optional if there is no such property or its value is undefined.
Link copied to clipboard
public abstract List<String> propertyNames()
Returns an immutable list of the names of the enumerable properties of this JavaScript object, including the properties from the prototype objects.
Link copied to clipboard
public abstract boolean putProperty(String name, @Nullable() Object value)
Creates a new property with the given name or updates the existing one in the current JavaScript object and returns true if the property with the given name was created or updated successfully.
Link copied to clipboard
public abstract boolean removeProperty(String name)
Removes a property with the given name in the JavaScript object and returns true if the property was successfully removed.
Link copied to clipboard
public abstract JsPromise then(JsPromiseHandler onFulfilled)
Registers a fulfillment handler for this promise and returns a new one.
public abstract JsPromise then(JsPromiseHandler onFulfilled, JsPromiseHandler onRejected)
Registers fulfillment and rejection handlers for this promise and returns a new one.